﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MipsMachine
{
	static class Program
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			
			
			if (args.Length == 0)
				Application.Run(new Editor());
			else
			{
				string arg_style = "";
				var files = new List<string>();
				var search = new List<string>();
				string output = "a.out";
				MipsAssembler asm = new MipsAssembler();
				for (int i = 0; i < args.Length; i++)
				{
					string arg = args[i].ToLower();
					switch (arg)
					{
						case "/s":
							arg_style = "srch";
							break;
						case "/f":
							arg_style = "";
							break;
						case "/o":
							arg_style = "outp";
							break;
						default:
							if (arg_style == "srch")
								search.Add(arg);
							else if(arg_style == "outp")
							{
								output = arg;
								arg_style = "";
							}
							else
								files.Add(arg);
							break;
					}
				}
				asm.SearchPaths.AddRange(search);
				var lst = new List<MipsAssembler.FilePair>();
				foreach (var item in files)
					lst.Add(new MipsAssembler.FilePair(item, search));
				var mipsprogram = new MipsProgram();
				asm.Assemble(lst, null, out mipsprogram, item => { Console.WriteLine(item.ToString()); });
			}

			return 0;
			
		}
	}
}
